package autoload

import (
	"fmt"
	"##PROJECT##/config/vars"
	"##PROJECT##/core/cConfig"
	"##PROJECT##/core/cRpc"
)

func initRpcClient() {
	clients := []cRpc.RpcClientInterface{
		//TODO:ImportRpcClient
	}

	clientHostMapping := make(map[string]cRpc.RpcClientInterface)
	for _, client := range clients {
		app, service := client.RpcClientName()
		name := fmt.Sprintf("%s.%s", app, service)
		clientHostMapping[name] = client
	}

	cConfig.ListenConf([]string{"RpcConf"}, func() {
		if vars.Rpc == nil || vars.Rpc.ServiceHosts == nil {
			return
		}
		for name, host := range vars.Rpc.ServiceHosts {
			if _, ok := clientHostMapping[name]; ok {
				clientHostMapping[name].RegisterServerHost(host)
			}
		}
	})
}
